package com.wushijia.sort;

import java.util.Arrays;

/**
 * 选择排序
 *
 * @author Administrator
 * @date 2021-06-15 10:56
 */
public class SelectSort {


  public static void main(String[] args) {
    int[] arr = {4, 1, 6, 9, 10, 22, 1, 7, 8, 100};

    for (int i = 0; i < arr.length; i++) {
      int min = i;

      for (int j = i + 1; j < arr.length; j++) {
        if (arr[j] < arr[min]) {
          min = j;
        }
      }

      swap(arr, i, min);
      System.out.println(Arrays.toString(arr));
    }
  }

  private static void swap(int[] arr, int i, int j) {
    int temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
  }
}
